package com.panshi.service.impl;

import com.panshi.mapper.ConsultingMapper;
import com.panshi.service.IConsultingService;
import com.panshi.tools.Consulting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ConsultingServiceImpl implements IConsultingService {

    @Autowired
    private ConsultingMapper consultingMapper;


    /***
     * 新增咨询
     * @param consulting
     */
    @Override
    public void addConsulting(Consulting consulting) {

        int userId = consulting.getUserId();
        String str = consulting.getEssayContent();
        if(str.length() >= 100){
            str=consulting.getEssayContent().substring(0,100);
        }
        consulting.setEssaySynopsis(str);
        // 新增审核表
        consultingMapper.addCheck(consulting);
        // 新增咨询表
        consultingMapper.addConsulting(consulting);
        System.out.println("2  =》addConsulting"+consulting);
        Consulting con = new Consulting();
        if(null != consulting.getEssayId()){
            con.setEssayId(consulting.getEssayId());
            con.setUserId(userId);
            // 新增动态表
            System.out.println("3  =》addConsulting"+con);
            consultingMapper.addDynamic(con);
        }
        // 新增搜索表
        consultingMapper.addEssay(consulting);
    }
}
